package com.example.demo.controller;

import com.example.demo.entity.Department;
import com.example.demo.entity.User;
import com.example.demo.repository.DepartmentRepository;
import com.example.demo.repository.UserRepository;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2017/11/18.
 */
@RestController
public class UserController {

    @Resource
    private UserRepository userRepository;
    @Resource
    private DepartmentRepository departmentRepository;

    /**
     * 测试关联查询
     * */
    @RequestMapping("/testUser")
    public String testUser() {

        Department department = new Department();
        department.setDeptname("dept1");
        departmentRepository.save(department);

        User u = new User();
        u.setName("user1");
        u.setDept(department);
        userRepository.save(u);

        return u.toString();
    }
}
